How to do it?:
Open the Rmarkdown file of this assignment (link) in Rstudio.
Right under each question, insert a code chunk (you can use the hotkey Ctrl + Alt + I to add a code chunk) and code the solution for the question.
Knit the rmarkdown file (hotkey: Ctrl + Alt + K) to export an html.
Publish the html file to your Githiub Page.
Submission: Submit the link on Github of the assignment to Blackboard.
Questions
Use the data of your own. Produce the following types of plots and comment on each plot. Plots should be meaningful. If you use the data we used in class, make sure the plots are not the same as the ones in the slides. All plots should have title, caption, appropriate labels on x and y-axis.
library(tidyverse)
library(lubridate)
library(ggplot2)
library(gganimate)
library(gifski)
df <- read_csv('https://covid19.who.int/WHO-COVID-19-global-data.csv')
df$month <- month(df$Date_reported)
d1 <- df %>% group_by(month, Country) %>% summarise(mean = mean(Cumulative_deaths))
d2 <- d1 %>% group_by(month) %>% mutate(rank=rank(-mean)) %>% ungroup()
d3 <- d2 %>% filter(rank <= 10)
ggplot(d3, mapping = aes(x=rank, y=mean, fill =Country, group=Country, label=Country)) + geom_col() + transition_states(month)+ scale_x_reverse()+geom_text(aes(y=mean, label= Country)) + labs(title='Month {closest_state}', x = '', y = 'Number of Cumulative Deaths', fill='Country')
df$week <- week(df$Date_reported)
d1 <- df %>% group_by(week, Country) %>% summarise(mean = mean(Cumulative_cases))
d2 <- d1 %>% group_by(week) %>% mutate(rank=rank(-mean)) %>% ungroup()
d3 <- d2 %>% filter(rank <= 5)
ggplot(d3, mapping = aes(x=rank, y=mean, fill =Country, group=Country, label=Country)) + geom_col() + transition_states(week)+ scale_x_reverse()+geom_text(aes(y=mean, label= Country)) + labs(title = 'Week {closest_state}', x = 'Country', y = 'Number of Cumulative Cases', fill='Country')
df <- read_csv('Temp_Data.csv')
df$year <- year(df$dt)
d1 <- df %>% filter(year >= '1950')
d2 <- d1 %>% group_by(City, year) %>% summarise(mean = mean(AverageTemperature))
d3 <- d2 %>% group_by(year) %>% mutate(rank = rank(-mean)) %>% ungroup()
d4 <- d3 %>% filter(rank<=5)
ggplot(d4, mapping = aes(x=rank, y=mean, fill =City, group=City, label=City)) + geom_col() + transition_states(year)+ scale_x_reverse()+geom_text(aes(y=mean, label= City)) + labs(title = '{closest_state}', x = 'City', y = 'Annual Average Tempurature', fill='City')